package com.summer.leetcode;

public class Solution3 {
    public static int lengthOfLongestSubstring(String s) {
        String tmpStr = "";
        int maxLength = 0;
        char[] c = s.toCharArray();
        for(int i = 0; i < c.length; i++) {
            char tmpChat = c[i];
//            while(tmpStr.indexOf(tmpChat) >= 0) {
//            	tmpStr = tmpStr.substring(1);
//            }
            int index = tmpStr.indexOf(tmpChat);
            if(index >= 0) {
            	tmpStr = tmpStr.substring(index + 1);
            }
            tmpStr += tmpChat;
            if(maxLength < tmpStr.length()) {
                maxLength = tmpStr.length();
            }
        }
        return maxLength;
    }
    
    public static void main(String[] args) {
		String[] caseStr = {
			"",
			"abcabcbb",
			"bbbbb",
			"pwwkew",
			"wewewesdfwsisjekqwos",
		};
		for(String str : caseStr) {
			int length = lengthOfLongestSubstring(str);
			System.out.println(str + ":" + length);
		}
	}
}
